import Vue from 'vue';
import VueRouter from 'vue-router';
import Layout from '../layout/index.vue';

Vue.use(VueRouter);

export const publicRoutes = [
  {
    path: '/',
    name: 'school',
    component: () => import('../school'),
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login'),
  },
  {
    path: '/layout',
    name: 'layout',
    component: Layout,
    redirect: '/dashboard/index',
    children: [
      {
        path: '/dashboard/index',
        name: 'dashboard',
        meta: { title: '概览', icon: 'dashboard' },
        component: () => import('../views/index'),
      },
    ]
  },
];



import group from './modules/group'
import flashsale from './modules/flashsale'
import coupon from './modules/coupon'
import mobile_index from './modules/mobile_index'
import pc_index from './modules/pc_index'
import video from './modules/video'
import column from './modules/column'
import media from './modules/media'
import audio from './modules/audio'
import bbs from './modules/bbs'
import question from './modules/question'
import testpaper from './modules/testpaper'
import book from './modules/book'
import setting_index from './modules/setting_index'
import staffs from './modules/staffs'
import role from './modules/role'



export const privateRoutes = [
  group,
  flashsale,
  coupon,
  mobile_index,
  pc_index,
  video,
  column,
  media,
  audio,
  bbs,
  question,
  testpaper,
  book,
  setting_index,
  staffs,
  role
];

const router = new VueRouter({
  routes: [...publicRoutes],
});


export function resetRouter() {
  const newRouter = new VueRouter({
    mode: 'hash', // 
    routes: publicRoutes,  //引入的公共路由
  });
  router.matcher = newRouter.matcher; // reset router
}


const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}






export default router;
